//
//  AppDelegate.m
//  xiaotianxin
//
//  Created by XYC on 2019/3/26.
//  Copyright © 2019 XYC. All rights reserved.
//

#import "AppDelegate.h"
#import "AFNetworking.h"
#import "XTXTool.h"
#import "XTXDengluViewController.h"

#import <GTSDK/GeTuiSdk.h>
@interface AppDelegate ()
{
    NSDictionary *dic1;
    UINavigationController *uihome;
    UINavigationController *uiGoddess;
    UINavigationController *uimy;
}

@property (nonatomic, strong) XTXDengluViewController *root1;
@property (nonatomic, strong) NSString *callid;


@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [NSUserDefaults.standardUserDefaults setFloat:UIApplication.sharedApplication.statusBarFrame.size.height forKey:@"zhuangtaiGao"];
   
    
    [NSUserDefaults.standardUserDefaults setFloat:UIApplication.sharedApplication.statusBarFrame.size.height forKey:@"zhuangtaiGao"];
    UIApplication *app = [UIApplication sharedApplication];
    app.applicationIconBadgeNumber = 0;
    [self Detectnetwork];
    [XTXTool share].user = [NSUserDefaults standardUserDefaults];
    
    [self appleauddit1];
    [XTXTool share].panduanshiqiantaihaishihoutai = 1;
    
    [UITabBar appearance].translucent = NO;
    return YES;
}

-(void)appleauddit1
{
    if (shifouDenglu) {
        [XTXGongTool.share dedaoyonghuxinxideClick];
        [XTXGongView tianjiasuoyoudeTabdekongzhiqijiazaiEventClick];
    }else{
        self.window = [[UIWindow alloc] init];
        self.window.frame = [UIScreen mainScreen].bounds;
        self.root1 = [[XTXDengluViewController alloc] init];
        UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:self.root1];
        self.window.rootViewController = nav1;
        [self.window makeKeyAndVisible];
    }
}

-(void)Detectnetwork{
    AFNetworkReachabilityManager *manager1 = [AFNetworkReachabilityManager sharedManager];
    [manager1 setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusNotReachable:
                [XTXTool share].islianjiewangluo =0;
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                [XTXTool share].islianjiewangluo =1;
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                [XTXTool share].islianjiewangluo =1;
                break;
            case AFNetworkReachabilityStatusUnknown:
                [XTXTool share].islianjiewangluo =0;
                break;
            default:
                break;
        }
    }];
    [manager1 startMonitoring];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    NSString *seclusionrestitution;
       if (@available(ios 13.0, *)) {
           if (![deviceToken isKindOfClass:[NSData class]]) return;
               const unsigned *tokenBytes = [deviceToken bytes];
               seclusionrestitution = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                                     ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                                     ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                                     ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
       }else{
           seclusionrestitution = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
           seclusionrestitution = [seclusionrestitution stringByReplacingOccurrencesOfString:@" " withString:@""];
       }
    
    NSLog(@"DeviceToken:%@",seclusionrestitution);

       [GeTuiSdk bindAlias:@"个推" andSequenceNum:seclusionrestitution];
       BOOL cheng =[GeTuiSdk registerDeviceToken:seclusionrestitution];
       if (cheng==YES) {
           NSLog(@"远程注册成功");
       }else{
           NSLog(@"远程注册失败");
       }
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    
    [XTXTool share].panduanshiqiantaihaishihoutai = 0;
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    [XTXTool share].panduanshiqiantaihaishihoutai = 0;
    XTXGongTool.share.shifouHota = YES;
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    //从后台进入前台
    [XTXTool share].panduanshiqiantaihaishihoutai = 1;
    XTXGongTool.share.shifouHota = NO;
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    [XTXTool share].panduanshiqiantaihaishihoutai = 1;
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

@implementation UIViewController(modalPresentationStyle)
 
- (UIModalPresentationStyle)modalPresentationStyle{
    return UIModalPresentationFullScreen;
}
@end
